home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / quarkpy / mapoptions.py < prev    next >
Text File  |  2004-01-05  |  10KB  |  241 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Implementation of QuArK Map editor's "Options" menu
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/quarkpy/mapoptions.py,v 1.10 2003/12/17 13:58:59 peter-b Exp $
  12.  
  13.  
  14.  
  15. import quarkx
  16. from qdictionnary import Strings
  17. from maputils import *
  18. import qmenu
  19.  
  20.  
  21.  
  22. def ToggleOption(item):
  23.     "Toggle an option in the setup."
  24.     tag = item.tog
  25.     setup = apply(quarkx.setupsubset, item.sset)
  26.     newvalue = not setup[tag]
  27.     setup[tag] = "1"[:newvalue]
  28.     if item.sendupdate[newvalue]:
  29.         quarkx.reloadsetup()
  30.  
  31.  
  32. def Config1Click(item):
  33.     "Configuration Dialog Box."
  34.     quarkx.openconfigdlg()
  35.  
  36. def Plugins1Click(item):
  37.     "Lists the loaded plug-ins."
  38.     import plugins
  39.     group = quarkx.newobj("Loaded Plug-ins:config")
  40.     for p in plugins.LoadedPlugins:
  41.         txt = p.__name__.split(".")[-1]
  42.         ci = quarkx.newobj("%s.toolbar" % txt)
  43.         try:
  44.             info = p.Info
  45.         except:
  46.             info = {}
  47.         for spec, arg in info.items():
  48.             ci[spec] = arg
  49.         ci["File"] = p.__name__
  50.         ci["Form"] = "PluginInfo"
  51.         try:
  52.             ci.shortname = info["plug-in"]
  53.         except:
  54.             pass
  55.         group.appenditem(ci)
  56.     quarkx.openconfigdlg("List of Plug-ins", group)
  57.  
  58.  
  59. def Options1Click(menu):
  60.     for item in menu.items:
  61.         try:
  62.             setup = apply(quarkx.setupsubset, item.sset)
  63.             item.state = not (not setup[item.tog]) and qmenu.checked
  64.         except:
  65.             try:
  66.                 tas = item.tas
  67.                 item.state = (quarkx.setupsubset(SS_MAP, "Options").getint("TexAntiScroll")==tas) and qmenu.radiocheck
  68.             except:
  69.                 pass
  70.         if item == lineThicknessItem:
  71.             item.thick = getLineThickness()
  72.             item.text = "Set Line Thickness (%1.0f)"%item.thick
  73.         
  74.  
  75. def toggleitem(txt, toggle, sendupdate=(1,1), sset=(SS_MAP,"Options"), hint=None):
  76.     item = qmenu.item(txt, ToggleOption, hint)
  77.     item.tog = toggle
  78.     item.sset = sset
  79.     item.sendupdate = sendupdate
  80.     return item
  81.  
  82.  
  83. def TasOption(item):
  84.     quarkx.setupsubset(SS_MAP, "Options").setint("TexAntiScroll", item.tas)
  85.     quarkx.reloadsetup(1)
  86.  
  87. def texantiscroll(txt, mode, hint="|Default/Sticky/Axis-sticky texture:\n\nIn QuArK, the textures are attached to polyhedrons in such a way that they follow all its movements. However, for easier texture alignment, you can set these options that only apply when scrolling polyhedrons (not rotating nor zooming).\n\nSTICKY : the textures don't move when you look at it standing in front of the face.\n\nAXIS-STICKY : the textures don't move when you look at it from the nearest axis direction.\n\nTo mimic the way QuArK and most other Quake editors work, choose AXIS-STICKY.|intro.mapeditor.menu.html#optionsmenu"):
  88.     item = qmenu.item(txt, TasOption, hint)
  89.     item.tas = mode
  90.     return item
  91.  
  92.  
  93. class LineThickDlg(SimpleCancelDlgBox):
  94.     #
  95.     # dialog layout
  96.     #
  97.     size = (160, 75)
  98.     dfsep = 0.7 
  99.     
  100.     dlgdef = """
  101.     {
  102.         Style = "9"
  103.         Caption = "Line Thickness Dialog"
  104.  
  105.         thick: =
  106.         {
  107.         Txt = "Line Thickness:"
  108.         Typ = "EF1"
  109.         Hint = "Needn't be an integer."
  110.         }
  111.         cancel:py = {Txt="" }
  112.     }
  113.     """
  114.  
  115.     def __init__(self, form, editor, m):
  116.     
  117.         src = quarkx.newobj(":")
  118.         thick =  quarkx.setupsubset(SS_MAP,"Options")['linethickness']
  119.         if thick:
  120.             thick=eval(thick)
  121.         else:
  122.             thick=3
  123.         src["thick"] = thick,
  124.         self.src = src
  125.         SimpleCancelDlgBox.__init__(self,form,src)
  126.  
  127.     def ok(self):
  128.         pass
  129.         thick = self.src['thick']    
  130.         if thick is not None:
  131.             thick, = thick
  132.             if thick==3:
  133.                 quarkx.setupsubset(SS_MAP,"Options")['linethickness']=""
  134.             else:
  135.                 quarkx.setupsubset(SS_MAP,"Options")['linethickness']="%4.2f"%thick
  136.  
  137. def getLineThickness():
  138.      thick =  quarkx.setupsubset(SS_MAP,"Options")['linethickness']
  139.      if thick:
  140.          return eval(thick)
  141.      else:
  142.          return 3
  143.      
  144. def getThinLineThickness():
  145.      thick =  getLineThickness()
  146.      if thick > 1:
  147.          thick = thick-1
  148.      return thick
  149.      
  150. def setLineThick(m):
  151.     editor = mapeditor()
  152.     if editor is None:
  153.         return
  154.     LineThickDlg(quarkx.clickform, editor, m)
  155.     
  156. lineThicknessItem = qmenu.item("Set Line Thickness (3)",setLineThick,"|Set Line Thickness:\n\nThis lets you set the thickness of certain lines that are drawn on the map, such as leak lines, portals, and targetting arrows.|intro.mapeditor.menu.html#optionsmenu")
  157.  
  158.  
  159. #
  160. # Global variables to update from plug-ins.
  161. #
  162.  
  163. items = [
  164.  
  165.     toggleitem("&Delete unused faces && polys", "DeleteFaces", (0,0),
  166.       hint="|Delete unused faces & polys:\n\nWhen you distort polyhedrons, some faces might become no longer used by the polyhedron, or the whole polyhedron could maybe become invalid (e.g. if it has no interior any more). When the option 'Delete unused faces & polys' is checked, QuArK will tell you about this and ask you if it should delete the no-longer-used objects.|intro.mapeditor.menu.html#optionsmenu"),
  167.  
  168.     toggleitem("&Secondary red lines", "RedLines2", (1,1),
  169.       hint="|Secondary red lines:\n\nDisplay two red lines per view instead of just one. These red lines let you select which part of the map is to be considered 'visible' on the other view. Invisible parts are grayed out and not selectable with the mouse.|intro.mapeditor.menu.html#optionsmenu"),
  170.  
  171.     toggleitem("3D &Models in textured views", "Entities", (1,1), (SS_GENERAL,"3D view"),
  172.       hint="|3D Models in textured views:\n\nDisplay actual models in solid and textured views.\n\nNote that this is not implemented for all the supported games yet. If you want to help about this, you are welcome !|intro.mapeditor.menu.html#optionsmenu"),
  173.  
  174.     toggleitem("&Quantize angles", "AutoAdjustNormal", (0,0),
  175.       hint="|Quantize angles:\n\nIf 'Quantize angles' is checked, you cannot set any angle for faces and entities : you can only set 'round' values. This command works like a grid for angles. You can set the step of this grid in the Configuration dialog box, Map, Building, 'Force angle to'.|intro.mapeditor.menu.html#optionsmenu"),
  176.  
  177.     toggleitem("&Paste objects at screen center", "Recenter", (0,0),
  178.       hint="|Paste objects at screen center:\n\nIf 'Paste objects at screen center' is checked, polyhedrons and entities are pasted from the clipboard near the screen center. If this option is not checked, they are pasted exactly where they were when you copied them to the clipboard. The latter option is useful to make several copies with a fixed step between them, but can be confusing because the pasted objects may be completely off the screen.|intro.mapeditor.menu.html#optionsmenu"),
  179.  
  180.     toggleitem("&Ignore groups marked so when building map", "IgnoreToBuild", (0,0),
  181.       hint="|Ignore groups marked so when building map:\n\nTo check complex maps with the game, you can choose not to include some parts of it in the test play. Do to so, you mark some groups as 'Ignore to build map' (right-click on a group for this command).\n\nMarked groups are actually ignored only if this option 'Ignore groups marked so when building map' is checked. You can uncheck it to play the whole map again without unmarking all groups one by one.|intro.mapeditor.menu.html#optionsmenu"),
  182.  
  183.     toggleitem("&Negative polys really dig in 3D views", "ComputePolys", (1,1),
  184.       hint="|Negative polys really dig in 3D views:\n\nIf this option is off, negative polyhedrons are shown as normal polyhedrons in textured view so that you can easily edit them. When this option is on, digging is performed and you don't see the negative polyhedron at all, but only the hole it made.\n\nIn non-software modes, in a future version of QuArK, the negative polyhedron itself should not be completely invisible, but transparent.|intro.mapeditor.menu.html#optionsmenu"),
  185.  
  186.     qmenu.sep,
  187.     texantiscroll("Default texture movement", 0),
  188.     texantiscroll("Sticky textures", 1),
  189.     texantiscroll("Axis-sticky textures", 2),
  190.     toggleitem("&Don't center L-square","DontCenterThreePoints", (0,0),
  191.       hint="|Don't center L-square:\n\nIf this item is on, threepoints aren't re-centered on face in texture positioning.|intro.mapeditor.menu.html#optionsmenu"),
  192.     lineThicknessItem
  193.     ]
  194. shortcuts = { }
  195.  
  196.  
  197. def OptionsMenu():
  198.     "The Options menu, with its shortcuts."
  199.  
  200.     PlugIns = qmenu.item("List of Plug-ins...", Plugins1Click, "lists loaded plug-ins")
  201.     Config1 = qmenu.item("Confi&guration...", Config1Click, "configuration dialog box")
  202.     Options1 = qmenu.popup("&Options", items+[qmenu.sep, PlugIns, Config1], Options1Click)
  203.     return Options1, shortcuts
  204.  
  205. # ----------- REVISION HISTORY ------------
  206. #
  207. #
  208. #$Log: mapoptions.py,v $
  209. #Revision 1.10  2003/12/17 13:58:59  peter-b
  210. #- Rewrote defines for setting Python version
  211. #- Removed back-compatibility with Python 1.5
  212. #- Removed reliance on external string library from Python scripts
  213. #
  214. #Revision 1.9  2003/03/28 02:55:24  cdunde
  215. #To update info and add infobase links.
  216. #
  217. #Revision 1.8  2003/03/24 10:36:57  tiglari
  218. #remove debug statement
  219. #
  220. #Revision 1.7  2003/03/23 07:30:13  tiglari
  221. #add getThinLineThickness function (1 unit less that ordinary line)
  222. #
  223. #Revision 1.6  2003/03/23 06:30:19  tiglari
  224. #change close to cancel button in linethickness dlg to fix error
  225. # noted by cdunde
  226. #
  227. #Revision 1.5  2003/03/21 10:56:08  tiglari
  228. #support for line-thickness specified by mapoption
  229. #
  230. #Revision 1.4  2001/08/28 22:43:54  tiglari
  231. #'Adjust angles automatically' renamed to `Quantize angles'
  232. #
  233. #Revision 1.3  2001/04/01 06:50:33  tiglari
  234. #don't recenter threepoints option added
  235. #
  236. #Revision 1.2  2000/06/02 16:00:22  alexander
  237. #added cvs headers
  238. #
  239. #
  240. #
  241.